import { defineStore } from "pinia";
import { DEFAULT_PRIMARY } from '@/config/config'
import pinia from '../index'

import type { SettingsState, ThemeConfigProps } from './model/settingsModel'

export const useSettingsStore = defineStore('app-settings',{
	state: ():SettingsState => ({
		collapse: false,
		refresh: false,
		themeConfig: {
			primary: DEFAULT_PRIMARY,
			isDark: false
		}
	}),
	actions:{
		changeCollapse(){
			this.collapse = !this.collapse;
		},
		setRefresh(){
			this.refresh = !this.refresh;
		},
		setThemeConfig(themeConfig: ThemeConfigProps){
			this.themeConfig = themeConfig
		}
	},
	// 报错到 localStorage
	persist: true,
})

export const useSettingsStoreWithOut = () => {
	return useSettingsStore(pinia)
}